// Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ------------------------------------------------------------------
// Modification history:
// feature: add fast heartbeat feature
// feature: destination order support by reception timestamp
// feature: QoS Profile Inheritance and Composition
// feature: Change the default order and test domain sope
// feature: simplify xml profile
// feature: support batch send
// feature: E2E Profile04 and Configuration Function Development
// feature: compatible with DSF
// feature: flowcontroller xml config and writer/reader-resourcelimit
// ------------------------------------------------------------------

#include <tinyxml2.h>

#include <xmlparser/XMLParserCommonPart.h>
#include <ertps/xmlparser/XMLParser.h>
#include <ertps/xmlparser/XMLProfileManager.h>

#include <cstring>
#include <regex>
#include <string>
#include <unordered_map>
#include <climits>

#include <elog/Log.hpp>
#include <asio.hpp>

namespace evbs {
namespace ertps {
namespace xmlparser {

XMLP_ret XMLParser::getXMLEnum(tinyxml2::XMLElement* elem, IntraprocessDeliveryType* e, uint8_t /*ident*/) {
    const char* text = nullptr;

    if ((nullptr == elem) || (nullptr == e)) {
        elogError(XMLPARSER, RetCode_t::RETCODE_ERROR, "nullptr when getXMLEnum XML_ERROR!");
        return XMLP_ret::XML_ERROR;
    } else if (nullptr == (text = elem->GetText())) {
        elogError(XMLPARSER, RetCode_t::RETCODE_ERROR, "<" << elem->Value() << "> getXMLEnum XML_ERROR!");
        return XMLP_ret::XML_ERROR;
    } else if (strcmp(text, xmlString::OFF) == 0) {
        *e = IntraprocessDeliveryType::INTRAPROCESS_OFF;
    } else if (strcmp(text, xmlString::USER_DATA_ONLY) == 0) {
        *e = IntraprocessDeliveryType::INTRAPROCESS_USER_DATA_ONLY;
    } else if (strcmp(text, xmlString::FULL) == 0) {
        *e = IntraprocessDeliveryType::INTRAPROCESS_FULL;
    } else {
        elogError(XMLPARSER, RetCode_t::RETCODE_ERROR,
                  "Node '" << xmlString::INTRAPROCESS_DELIVERY << "' with bad content");
        return XMLP_ret::XML_ERROR;
    }

    return XMLP_ret::XML_OK;
}

}  // namespace xmlparser
}  // namespace ertps
}  // namespace evbs
